package cn.bincker.mycaptcha.slider;

import cn.bincker.mycaptcha.basic.properties.CacheConfigProperties;
import cn.bincker.mycaptcha.basic.properties.ImageCaptchaProperties;
import cn.bincker.mycaptcha.basic.properties.ShadowProperties;
import cn.bincker.mycaptcha.utils.ColorUtils;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.awt.Color;
import java.io.File;
import java.util.List;

@Getter
@Setter
@ConfigurationProperties("my-captcha.slider")
public class SliderCaptchaProperties implements ImageCaptchaProperties {
    private Boolean enabled = true;
    private String path = "/my-slider-captcha";
    private List<String> protectPathList = DEFAULT_PROTECT_PATH_LIST;
    private File imageFilePath = new File(DEFAULT_IMAGE_PATH);
    private Integer width = DEFAULT_WIDTH;
    private Integer height = DEFAULT_HEIGHT;
    private CacheConfigProperties cache = new CacheConfigProperties(new File(".captcha-cache/slider"));
    private Long survivalTime = 60000L * 5;

    /**
     * 容错值
     * 表示滑块位置只要不超出多少则算正确
     */
    private Integer faultToleranceValue = 5;

    /**
     * 滑块大小
     */
    private Integer sliderSize = 120;

    /**
     * 验证码上的滑块内阴影
     */
    private ShadowProperties imageSliderShadow = new ShadowProperties(true, 1, 1, 1, 3, Color.BLACK);

    /**
     * 验证码滑块蒙板颜色
     */
    private Color imageSliderMaskColor = Color.BLACK;

    public void setImageSliderMaskColor(String hexColor) {
        this.imageSliderMaskColor = ColorUtils.decodeColor(
                hexColor,
                Color.BLACK
        );
    }

    /**
     * 验证码滑块蒙板透明度
     */
    private Float imageSliderMaskAlpha = .1f;

    /**
     * 验证码滑块蒙板透明度浮动范围0~(1 - imageSliderMaskAlpha)
     */
    private Float imageSliderMaskAlphaFloatingRange = .1f;

    /**
     * 滑块内阴影
     */
    private ShadowProperties sliderInsetShadow = new ShadowProperties(true, 2, 0, 0, 2, Color.WHITE);

    /**
     * 滑块外阴影
     */
    private ShadowProperties sliderOutsetShadow = new ShadowProperties(true, 2, 0, 0, 10, Color.BLACK);

    /**
     * 虚滑块数量
     */
    private Integer fakeSliderNumber = 1;

    /**
     * 与最左边的距离
     */
    private Integer marginLeft = 50;
}
